<?php $this->load->view('layout/header'); ?>
<div class="container-fluid tourism-goods-add-step2">
    <div class="row-fluid">
        <div class="span12">
            <h3 class="page-title">商家账号关联<small>手续费分润</small></h3>
            <?php echo breadcrumb(array('userrelatedself/grid' => '商家账号关联', "userrelatedself/addprofit/".$id => '手续费分润')); ?>
        </div>
    </div>
    <div class="alert alert-error" style="display:none;">
        <button data-dismiss="alert" class="close"></button>
        <a href="javascript:;" class="glyphicons no-js remove_2"><i></i><p></p></a>
    </div>
    <div class="row-fluid">
        <div class="span12">
            <div class="portlet box green">
                <div class="portlet-title">
                    <div class="caption"><i class="icon-plus-sign"></i>编辑添加手续费分润</div>
                    <div class="tools">
                        <a class="collapse" href="javascript:;"></a>
                        <a class="remove" href="javascript:;"></a>
                    </div>
                </div>
                <div class="portlet-body form">
                    <form class="form-horizontal provider-profit-form" method="post" enctype="multipart/form-data">
                        <div class="alert alert-success">手续费分润基本信息</div>
                        <div class="control-group add-supplieruid-html">
                            <label class="control-label"><em>* </em>账号信息</label>
                            <div class="controls">
                                <input type="text" name="provider_uid" value="<?php echo '供应商('.$usereLated->provider_uid.')---分销商('.$usereLated->reseller_uid.')';?>" class="m-wrap span4" disabled="disabled"/>
                                <input type="hidden" name="user_related_id" value="<?php echo $usereLated->id;?>" />
                                <input type="hidden" name="solve_type" value="<?php echo $poundageProfit->num_rows() > 0 ? 1 : 2;?>" />
                            </div>
                        </div>
                        <div class="alert alert-success">手续费分润</div>
                        <div class="row-fluid add-supplieruid-html">
                            <div class="span12 pricing pricing-active hover-effect">
                                <div class="pricing-head pricing-head-active">
                                    <h3>手续费分润</h3>
                                </div>
                                <ul class="pricing-content unstyled">
                                    <?php if ($poundageProfit->num_rows() > 0): ?>
                                        <?php foreach ($poundageProfit->result() as $row): ?>
                                            <li>
                                                <i class="icon-tags"></i>
                                                <select name="type_id[]" class="m-wrap span2">
                                                    <?php foreach ($userType as $value):?>
                                                        <option value="<?php echo $value->type_id; ?>" <?php if ($value->type_id == $row->bit_trade):?>selected="selected"<?php endif;?> > <?php echo $value->type_name; ?></option>
                                                    <?php endforeach;?>
                                                </select>
                                                <input type="text" name="uid[]" value="<?php echo $row->uid; ?>" class="m-wrap span3 supplieruid required tooltips" placeholder="账号UID" data-original-title="双击可弹框选择供应商；直接输入‘用户名称或编号’可提示" data-trigger="hover">
                                                <span>手续费(%) </span><input type="text" name="poundage[]" value="<?php echo $row->poundage; ?>" class="m-wrap span6 required " placeholder="请填写1到100整数">
                                                <a href="javascript:void(0);" class="btn mini profit_delete">删除</a>
                                            </li>
                                        <?php endforeach; ?>
                                    <?php endif; ?>
                                </ul>
                                <div class="pricing-footer">
                                    <a id="profit_add" class="btn green" href="javascript:void(0);">添加分润人 <i class="m-icon-swapright m-icon-white "></i></a>
                                </div>
                            </div>
                        </div>
                        <div class="form-actions">
                            <button class="btn green" type="submit"><i class="icon-ok"></i> 保存</button>
                            <a class="btn" href="<?php echo base_url('userrelatedself/grid')?>">返回上一步</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
$(document).ready(function(){
    
    $("#profit_add").click(function () {
        var _val = '<li><i class="icon-tags"></i> <select name="type_id[]" class="m-wrap span2"><?php foreach ($userType as $value):?><option value="<?php echo $value->type_id;?>" > <?php echo $value->type_name;?></option><?php endforeach;?></select> <input class="m-wrap span3 required supplieruid tooltips" type="text" name="uid[]" value="0" placeholder="账号UID" data-original-title="双击可弹框选择供应商；直接输入‘用户名称或编号’可提示" data-trigger="hover" /> 手续费(%)<input class="m-wrap span6 required number" type="text" name="poundage[]" value="0" placeholder="请填写1到100整数"> <a href="javascript:void(0);" class="btn mini profit_delete">删除</a></li>';
        $(this).parent('.pricing-footer').prev().append(_val);
    });
    $('ul.pricing-content').on('click', ".profit_delete", function () {
        $(this).parent('li').remove();
    });

    // 提交验证
    $('form.provider-profit-form').submit(function () {
        return false;
    }).validate({
        submitHandler: function (f) {
            $.ajax({
                type: 'post',
                async: true,
                dataType: 'json',
                url: hostUrl() + '/userrelatedself/ajaxValidate',
                data: $('form.provider-profit-form').serialize(),
                success: function (data) {
                    if (data.status) {
                        $('.alert-error').hide();
                        window.location.href = data.messages;
                    } else {
                        $('.alert-error').show();
                        $('.alert-error .remove_2 p').html(data.messages);
                        var body = (window.opera) ? (document.compatMode == 'CSS1Compat' ? $('html') : $('body')) : $('html,body');
                        body.animate({scrollTop: $('.page-container').offset().top}, 1000);
                    }
                }
            });
        }
    });
});
</script>
<?php $this->load->view('user/addSupplierUid/ajaxGetUser');?>
<?php $this->load->view('layout/footer'); ?>
